{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2e66eb97",
   "metadata": {},
   "source": [
    "# 创建直方图\n",
    "在 Matplotlib 中，我们使用 hist() 函数来创建直方图。\n",
    "\n",
    "hist() 函数将使用一个数字数组来创建直方图，该数组作为参数发送到函数中。\n",
    "\n",
    "为简单起见，我们使用 NumPy 随机生成一个包含 250 个值的数组，其中值将集中在 170 左右，标准差为 10。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f77363c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8c06f3a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[148.19624927 172.46162139 178.74234621 169.00762883 162.98327556\n",
      " 161.56646537 161.93323798 177.91248196 183.35583519 175.83105577\n",
      " 177.48372658 173.9105277  167.6167365  156.45839837 184.71126105\n",
      " 147.56722584 174.94510527 179.96020255 174.40346562 175.29157962\n",
      " 166.11195587 162.34964354 164.48594168 157.60887203 149.87077232\n",
      " 169.3191455  158.16639172 190.93709618 169.46965313 182.07266314\n",
      " 168.00837279 152.10610662 177.47235585 186.44853006 165.66710554\n",
      " 178.61131775 167.34385217 171.44719982 136.51074858 169.53017288\n",
      " 179.34967775 165.05529126 171.78956422 160.38446426 164.93211435\n",
      " 169.49660684 176.44295735 171.85848669 178.67543042 161.72560146\n",
      " 178.05648599 182.80951936 167.5532368  158.1569202  183.79123769\n",
      " 166.78236909 149.66828236 171.90640592 156.62648238 161.13683932\n",
      " 171.63186185 171.21190147 172.37210302 169.74806037 170.5105446\n",
      " 165.38015077 155.43036858 178.13488439 172.58036066 177.30866278\n",
      " 185.51942794 156.24107456 182.18003617 181.86305562 178.71310802\n",
      " 188.44193519 171.74710375 162.21716442 185.77642092 175.24812282\n",
      " 172.52452794 167.37129701 172.95538155 167.42712524 174.3743424\n",
      " 175.90566135 181.00669438 165.46531656 182.65242195 174.98932509\n",
      " 168.54538837 168.73533089 167.87691936 163.54185551 169.09820437\n",
      " 180.25583475 168.75834776 183.67879746 177.67860544 172.50068452\n",
      " 169.27911449 175.96514505 166.28821012 183.01015556 177.9900049\n",
      " 192.26763622 165.39436299 152.73635406 163.90542069 184.22573331\n",
      " 174.97418545 177.89956599 167.73381259 155.34650032 171.86978861\n",
      " 164.4753206  186.38667199 181.14730366 175.9768615  172.98346874\n",
      " 176.29495816 174.68711142 171.98012557 168.05547726 167.02902357\n",
      " 160.29032684 169.41148826 172.70971263 168.05491964 180.85331849\n",
      " 159.2727311  186.18916368 167.8871124  167.86249497 171.90559556\n",
      " 163.4423881  160.41725453 160.27713008 173.33864831 162.68594188\n",
      " 180.56899807 161.79899684 193.07811041 179.40104219 168.54639041\n",
      " 178.10578755 159.64239758 173.47606402 170.98901722 177.66897613\n",
      " 186.71086686 187.6292421  168.34323158 165.82172179 160.97323531\n",
      " 162.1232546  187.43929121 176.19443271 165.80752771 161.20422216\n",
      " 188.77061321 168.07380009 157.20455622 155.10649852 166.9781992\n",
      " 153.92281203 156.23484214 166.94533356 180.62908021 159.52567675\n",
      " 156.01921523 156.16086968 178.97920456 165.44249987 174.74849242\n",
      " 180.96153538 184.02815432 172.28967054 175.37427831 174.59919013\n",
      " 176.07417794 168.48615192 154.56511775 168.46084188 164.31665603\n",
      " 162.8474534  173.25959761 165.64771653 173.42531123 178.92189576\n",
      " 170.23381972 165.59637233 144.37402991 189.40857909 168.71994852\n",
      " 164.95808396 167.12798619 174.97740003 169.35462902 168.58176684\n",
      " 164.97909082 173.44279355 168.12309996 170.13128277 167.77019937\n",
      " 169.25783519 172.58496298 169.42454336 172.30342043 176.51774422\n",
      " 152.44594287 185.48117671 190.62673    173.97078032 164.3306784\n",
      " 161.40300527 164.64845074 161.16462708 165.69613022 176.04472741\n",
      " 166.67210376 169.61030226 181.64020124 192.91511629 155.93256868\n",
      " 157.26952668 171.93389482 169.96930565 156.58115973 181.71064049\n",
      " 161.23891432 159.56527997 157.06345896 175.76313421 180.31190034\n",
      " 173.70489441 172.76583748 172.19133442 141.5132693  172.09165819\n",
      " 171.515399   179.92439064 159.60872251 173.97465683 177.95304813\n",
      " 174.66655781 173.4653287  159.09833556 184.90836987 157.51840048]\n"
     ]
    }
   ],
   "source": [
    "x = np.random.normal(170, 10, 250)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7339663e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOYElEQVR4nO3dfZBd9V3H8fenSaFa2wKyZDKEuJkW2uEfHroinT5Noa0tcQxqzcA4mrGZyVhth9ZqDdXp1NE/gk+IM06dCNhUawGxlQhjLcYi40wb2PBMAXkwDEkD2VrQ1j9A2q9/3BOzbm7Ym929e/e3vF8zO/ec3zk35/udy/3w23PvOZuqQpLUnleMugBJ0twY4JLUKANckhplgEtSowxwSWrUysU82Mknn1zj4+OLeUhJat6ePXu+VVVjM8cXNcDHx8eZnJxczENKUvOSPNlv3FMoktQoA1ySGmWAS1KjDHBJapQBLkmNMsAlqVEGuCQ1ygCXpEYZ4JLUqEW9ElNaqsa33jKyY+/dtn5kx1bbnIFLUqMMcElq1EABnuSEJDcmeTjJQ0nekuSkJLcmebR7PHHYxUqSDht0Bn4V8OWqehNwFvAQsBXYVVWnA7u6dUnSIpk1wJO8DngHcA1AVb1QVc8BG4Ad3W47gIuHU6IkqZ9BZuDrgCngL5LcneTqJK8GVlXVgW6fp4FV/Z6cZEuSySSTU1NTC1O1JGmgAF8JnAt8pqrOAf6bGadLqqqA6vfkqtpeVRNVNTE2dsQflJAkzdEgAb4P2FdVu7v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ywCWpUf8LSxqB65eD9mQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.hist(x)\n",
    "plt.show() "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
